﻿using B.S.ProcessEngine.ErrorCode;
using B.S.SmartStorPro.Read.API.AppLication.Login;
using B.S.SmartStorPro.Read.API.DTO;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity.Data;
using Microsoft.AspNetCore.Mvc;

namespace B.S.SmartStorPro.Read.API.Controllers
{
    // 控制器类
    [ApiController]
    [Route("[controller]")]
    public class LoginController : ControllerBase
    {
        private readonly IMediator mediator;

        public LoginController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="log">登录命令</param>
        /// <returns>返回 API 结果</returns>
        [HttpPost]
        public async Task<APIResult<UserDTO>> Login([FromBody] LoginCommand log)
        {
            try
            {
                return await mediator.Send(log);
            }
            catch (Exception)
            {
                // 这里可以添加更详细的异常处理逻辑
                throw;
            }
        }
    }

}
